<template>
  <div class="app-container app-content">
    <el-row class="line-bottom" v-show="showSearch">
      <el-col class="form_col">
        <el-form :model="queryParams" ref="queryForm" :size="formItemSize" v-show="showSearch"
                 :label-width="labelWidth">
          <div id="searchFilter" style="display: flex; flex-wrap: wrap">
            <el-form-item label="用户名称" prop="userName">
              <el-input
                  v-model="queryParams.userName"
                  placeholder="请输入用户名称"
                  clearable
                  @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="用户编号" prop="userId">
              <el-input
                  v-model="queryParams.userId"
                  placeholder="请输入用户编号"
                  clearable
                  @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="品牌名称" prop="brandName">
              <el-input
                  v-model="queryParams.brandName"
                  placeholder="请输入品牌名称"
                  clearable
                  @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <!-- <el-form-item label="所属客户" prop="tenantId">
              <el-select filterable v-model="queryParams.tenantId" placeholder="请选择所属客户" style="width: 100%">
                <el-option
                  v-for="dept in deptOption"
                  :key="dept.tenantId"
                  :label="dept.deptName"
                  :value="dept.tenantId"
                ></el-option>
              </el-select>
            </el-form-item> -->
            <el-form-item label="状态" prop="userMark">
              <el-select v-model="queryParams.userMark" placeholder="请选择用户状态"  style="width: 100%;">
                <el-option v-for="dict in dict.type.user_mark" :key="dict.value" :label="dict.label"
                          :value="parseInt(dict.value)"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="退场时间">
              <el-date-picker 
                v-model="dateRangeReadDate" value-format="yyyy-MM-dd HH:mm:ss"
                type="datetimerange" range-separator="-" start-placeholder="开始日期"
                end-placeholder="结束日期" style="width: 100%;" :default-time="['00:00:00', '23:59:59']"></el-date-picker>
            </el-form-item>
            <!-- <el-form-item label="房间号" prop="userId">
              <el-input
                  v-model="queryParams.userId"
                  placeholder="请输入房间号"
                  clearable
                  @keyup.enter.native="handleQuery"
              />
            </el-form-item> -->
          </div>
        </el-form>
      </el-col>

      <el-col class="form_query">
        <el-button v-show="collapseAble" type="text" @click="shiftCollapseAble" class="text">
              <span>
                {{ fold ? '收起筛选' : '更多筛选' }}
              </span>
        </el-button>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-col>
    </el-row>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['basedata:usersxb:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['basedata:usersxb:remove']"
        >批量删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="el-icon-upload2"
            size="mini"
            @click="handleImport"
            v-has-permi="['basedata:userxb:import']"
        >导入
        </el-button>
      </el-col>

      <RightDropdown :columns="columns" :showSearch.sync="showSearch" :uploadVisible="uploadVisible"
                     @queryTable="getList" @export="handleExport" @upload="handleUpload"
                     :hasPermiExport="['basedata:usersxb:export']"></RightDropdown>
    </el-row>

    <el-table v-loading="loading" :data="usersxbList" size="mini" row-key="id" border :height="getAvailableHeight"
              @selection-change="handleSelectionChange" default-expand-all
              :tree-props="{children: 'children', hasChildren: 'hasChildren'}" :default-sort="defaultSort"
              @sort-change="handleSorterChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="所属客户" align="center" prop="deptName" width="120" v-if="columns[9].visible"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="用户编号" align="center" prop="userId" width="100" v-if="columns[0].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']"/>
      <el-table-column label="用户名称" align="center" prop="userName" v-if="columns[1].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']"/>
      <!-- <el-table-column label="用户手机号码" align="center" prop="userPhone" width="130" v-if="columns[2].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']"/>
      <el-table-column label="证件类型" align="center" prop="idType" v-if="columns[3].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']"/>
      <el-table-column label="证件号码" align="center" prop="userCode" v-if="columns[4].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']"/>
      <el-table-column label="用户通讯地址" align="center" prop="userAddress" width="140" v-if="columns[5].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']"/>
      <el-table-column label="备注" align="center" prop="remark" v-if="columns[6].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']"/> -->
      <el-table-column label="品牌名称" align="center" prop="brandName" v-if="columns[10].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']"/>
      <el-table-column label="用户状态" align="center" prop="userMark" width="100" v-if="columns[7].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_mark" :value="scope.row.userMark"/>
        </template>
      </el-table-column>
      <el-table-column label="立户时间" align="center" prop="createTime" v-if="columns[8].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="入场时间" align="center" prop="admissionTime" v-if="columns[8].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']">
        <template slot-scope="scope">
          <span>{{ scope.row.admissionTime == null ? '-' : scope.row.admissionTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="离场时间" align="center" prop="departureTime" v-if="columns[8].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']">
        <template slot-scope="scope">
          <span>{{ scope.row.departureTime == null ? '-' : scope.row.departureTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="离场开账" align="center" prop="leaveBillStatus" width="100" v-if="columns[7].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.leave_bill_status" :value="scope.row.leaveBillStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="是否预存" align="center" prop="isPrepayment" width="100" v-if="columns[7].visible"
                       :show-overflow-tooltip="true" sortable="custom"
                       :sort-orders="['ascending', 'descending']">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.is_prepayment" :value="scope.row.isPrepayment"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
        <template slot-scope="scope">
          <el-tooltip effect="dark" content="修改" placement="top">
            <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['basedata:usersxb:edit']"
            >
            </el-button>
          </el-tooltip>
          <el-tooltip effect="dark" v-show="scope.row.userMark === 1" content="离场开账" placement="top">
            <el-button
                size="mini"
                type="text"
                icon="el-icon-s-check"
                @click="handleLeave(scope.row)"
                v-hasPermi="['basedata:usersxb:edit']"
            >
            </el-button>
          </el-tooltip>
          <el-tooltip effect="dark"  v-show="scope.row.userMark === 1" content="挂接" placement="top">
            <el-button
                size="mini"
                type="text"
                icon="el-icon-set-up"
                @click="handleSetting(scope.row)"
                v-hasPermi="['basedata:usersxb:edit']"
            >
            </el-button>
          </el-tooltip>

          <el-tooltip effect="dark" v-show="scope.row.userMark === 0" content="克隆" placement="top">
            <el-button
                size="mini"
                type="text"
                icon="el-icon-s-finance"
                @click="handleClone(scope.row)"
                v-hasPermi="['basedata:usersxb:edit']"
            >
            </el-button>
          </el-tooltip>

          <el-tooltip effect="dark" content="删除" placement="top">
            <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['basedata:usersxb:remove']"
            >
            </el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改区域管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" :close-on-click-modal="false" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="用户编号" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户编号"/>
        </el-form-item>
        <el-form-item label="用户名称" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户名称"/>
        </el-form-item>
        <el-form-item label="所属客户" prop="tenantId">
          <el-select filterable v-model="form.tenantId" placeholder="请选择所属客户" style="width: 100%;">
            <el-option
              v-for="dept in deptOption"
              :key="dept.tenantId"
              :label="dept.deptName"
              :value="dept.tenantId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机号码" prop="userPhone">
          <el-input v-model="form.userPhone" placeholder="请输入用户手机号码"/>
        </el-form-item>
        <el-form-item label="证件类型" prop="idType">
          <el-input v-model="form.idType" placeholder="请输入证件类型"/>
        </el-form-item>
        <el-form-item label="证件号码" prop="userCode">
          <el-input v-model="form.userCode" placeholder="请输入证件号码"/>
        </el-form-item>
        <el-form-item label="用户通讯地址" prop="userAddress">
          <el-input v-model="form.userAddress" placeholder="请输入用户通讯地址"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注"/>
        </el-form-item>
        <el-form-item label="用户状态" prop="userMark">
          <el-select v-model="form.userMark" placeholder="请选择用户状态" disabled style="width: 100%;">
            <el-option v-for="dict in dict.type.user_mark" :key="dict.value" :label="dict.label"
                       :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预存账户" prop="isPrepayment">
          <el-select v-model="form.isPrepayment" placeholder="请选择预存账户" style="width: 100%;">
            <el-option v-for="dict in dict.type.is_prepayment" :key="dict.value" :label="dict.label"
                       :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="入场时间" prop="admissionTime">
          <el-date-picker type="datetime" placeholder="选择入场时间" v-model="form.admissionTime" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"></el-date-picker>
        </el-form-item>
        <el-form-item label="离场时间" prop="departureTime">
          <el-date-picker type="datetime" placeholder="选择入场时间" v-model="form.departureTime" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"></el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

<!-- 克隆区域管理对话框 -->
<el-dialog :title="clonetitle" :visible.sync="cloneopen" width="500px" :close-on-click-modal="false" append-to-body>
      <el-form ref="cloneform" :model="cloneform" :rules="rules" label-width="100px">
        <el-form-item label="用户编号" prop="userId">
          <el-input v-model="cloneform.userId" placeholder="请输入用户编号"/>
        </el-form-item>
        <el-form-item label="用户名称" prop="userName">
          <el-input v-model="cloneform.userName" placeholder="请输入用户名称"/>
        </el-form-item>
        <el-form-item label="所属客户" prop="tenantId">
          <el-select filterable v-model="cloneform.tenantId" placeholder="请选择所属客户" style="width: 100%;">
            <el-option
              v-for="dept in deptOption"
              :key="dept.tenantId"
              :label="dept.deptName"
              :value="dept.tenantId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机号码" prop="userPhone">
          <el-input v-model="cloneform.userPhone" placeholder="请输入用户手机号码"/>
        </el-form-item>
        <el-form-item label="证件类型" prop="idType">
          <el-input v-model="cloneform.idType" placeholder="请输入证件类型"/>
        </el-form-item>
        <el-form-item label="证件号码" prop="userCode">
          <el-input v-model="cloneform.userCode" placeholder="请输入证件号码"/>
        </el-form-item>
        <el-form-item label="用户通讯地址" prop="userAddress">
          <el-input v-model="cloneform.userAddress" placeholder="请输入用户通讯地址"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark" v-show="false">
          <el-input v-model="cloneform.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="用户状态" prop="userMark">
          <el-select v-model="cloneform.userMark" placeholder="请选择用户状态" disabled style="width: 100%;">
            <el-option v-for="dict in dict.type.user_mark" :key="dict.value" :label="dict.label"
                       :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预存账户" prop="isPrepayment">
          <el-select v-model="cloneform.isPrepayment" placeholder="请选择预存账户" style="width: 100%;">
            <el-option v-for="dict in dict.type.is_prepayment" :key="dict.value" :label="dict.label"
                       :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="入场时间" prop="admissionTime">
          <el-date-picker type="datetime" placeholder="选择入场时间" v-model="cloneform.admissionTime" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"></el-date-picker>
        </el-form-item>
        <el-form-item label="离场时间" prop="departureTime">
          <el-date-picker type="datetime" placeholder="选择入场时间" v-model="cloneform.departureTime" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"></el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cloneSubmitForm">确 定</el-button>
        <el-button @click="clonecancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
          ref="upload"
          :limit="1"
          accept=".xlsx, .xls"
          :headers="upload.headers"
          :action="upload.url + '?updateSupport=' + upload.updateSupport"
          :disabled="upload.isUploading"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :auto-upload="false"
          drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport"/>
            是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <!-- <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link> -->
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 办理离场 -->
    <!-- <el-dialog title="办理离场-手动抄表" :visible.sync="leaveOpen" width="500px" :close-on-click-modal="false" append-to-body> -->
      <el-dialog :title="title_userLeve" :visible.sync="leaveOpen" :fullscreen="isFullscreen" append-to-body  :show-close="false" width="1180px" :close-on-click-modal="false" >
     
    <template #title>
         <div class="custom-dialog-header">
          <!-- 原始标题 -->
          <span  class="custom-dialog-title" >{{ title_userLeve }}</span>
          <!-- 自定义最大化/还原按钮 -->
          <!-- <el-button
            type="text"
            size="mini"
            
            @click.stop="toggleMaximize"
            :icon="isFullscreen ? 'el-icon-minus' : 'el-icon-full-screen'"
          ></el-button> -->
          <div class="custom-dialog-actions">
          <el-button
              type="text"
              size="mini"
              class="custom-dialog-btn"
              @click.stop="toggleMaximize"
            >
              <i :class="isFullscreen ? 'el-icon-minus' : 'el-icon-full-screen'"></i>
            </el-button>

            <el-button
              type="text"
              size="mini"
              class="custom-dialog-btn custom-dialog-close-btn"
              @click.stop="leaveOpen = false"
            >
              <i class="el-icon-close"></i>
            </el-button>
              </div>
        </div>
      </template>
      <el-steps :active="steps_active" simple>
        <el-step title="离场用户的相关设备" icon="el-icon-edit"></el-step>
        <el-step title="相关公摊的设备" icon="el-icon-upload"></el-step>
        <el-step title="生成开账报表" icon="el-icon-picture"></el-step>
      </el-steps>
      <div :class="[isFullscreen ? 'div-height-full-screen':'div-height-minus']">
        <!-- <el-date-picker type="datetime" placeholder="离场时间" v-model="userdepartureTime" value-format="yyyy-MM-dd HH:mm:ss" style="width: 30%;" @change="getTerminalList"></el-date-picker>
         -->
         
        <el-form ref="leaveForm" :model="leaveForm" label-width="100px" label-position="top">
          
          <div v-show="steps_active==1" >
            <el-form-item label="离场时间">
                  <el-date-picker type="datetime" placeholder="输入离场时间" v-model="userdepartureTime" value-format="yyyy-MM-dd HH:mm:ss" style="width: 30%;" @change="getTerminalList"></el-date-picker>
            </el-form-item>
            
          
          <el-divider content-position="left" v-show="leaveForm.userWaterTerminalListForNoH!=null && leaveForm.userWaterTerminalListForNoH.length!==0">水表设备</el-divider>
          <el-form-item required
            v-for="(domain, index) in leaveForm.userWaterTerminalListForNoH"
              :label="'安装地址：'+domain.terminalName+',设备编号：'+domain.terminalId"
              :key="domain.locationNb"
          >
          
            <div>
              <el-col :span="7">
                <el-form-item :prop="'userWaterTerminalListForNoH.' + index + '.totalFlow'"
                  :rules="[{ required: true, message: '读数不能为空', trigger: 'blur' },{ validator:checkNumber, trigger: 'blur' }]">
                  <el-input v-model="domain.totalFlow" placeholder="累计流量"></el-input>
                </el-form-item>
              </el-col>
              <el-col class="line" :span="1">-</el-col>
              <el-col :span="7">
                <el-form-item :prop="'userWaterTerminalListForNoH.' + index + '.readNumber'"
                  :rules="[{ required: true, message: '读数不能为空', trigger: 'blur' },{ validator:checkNumber, trigger: 'blur' }]">
                  <el-input v-model="domain.readNumber" placeholder="正向读数"></el-input>
                </el-form-item>
              </el-col>
              <el-col class="line" :span="1">-</el-col>
              <el-col :span="7">
                <el-form-item :prop="'userWaterTerminalListForNoH.' + index + '.reverseNumber'"
                  :rules="[{ required: true, message: '读数不能为空', trigger: 'blur' },{ validator:checkNumber, trigger: 'blur' }]">
                  <el-input v-model="domain.reverseNumber" placeholder="反向读数"></el-input>
                </el-form-item>
              </el-col>
            </div>
           
          </el-form-item>
          <el-divider content-position="left" v-show="leaveForm.userElectricityTerminalListForNoH!=null && leaveForm.userElectricityTerminalListForNoH.length!==0">电表设备</el-divider>
          <el-form-item required
            v-for="(domain, index) in leaveForm.userElectricityTerminalListForNoH"
              :label="'安装地址：'+domain.terminalName+',设备编号：'+domain.terminalId"
              :key="domain.locationNb"
          >
            <div>
              <el-form-item :prop="'userElectricityTerminalListForNoH.' + index + '.totalFlow'"
                :rules="[{ required: true, message: '读数不能为空', trigger: 'blur' },{ validator:checkNumber, trigger: 'blur' }]">
                <el-input v-model="domain.totalFlow" placeholder="组合有功电量"></el-input>
              </el-form-item>
            </div>
        
           
          </el-form-item>
        </div>
        <div v-show="steps_active==2">
          <el-divider content-position="left" v-show="leaveForm.otherWaterTerminalListForNoH!= null &&leaveForm.otherWaterTerminalListForNoH.length!==0">水表设备</el-divider>
          <el-form-item
            v-for="(domain, index) in leaveForm.otherWaterTerminalListForNoH"
              :label="'安装地址：'+domain.terminalName+',设备编号：'+domain.terminalId"
              :key="domain.locationNb"
          > <!--required-->
          
            <div>
              <el-col :span="7">
                <el-form-item :prop="'otherWaterTerminalListForNoH.' + index + '.totalFlow'" >
                  <el-input v-model="domain.totalFlow" placeholder="累计流量"></el-input>
                </el-form-item>
              </el-col>
              <el-col class="line" :span="1">-</el-col>
              <el-col :span="7">
                <el-form-item :prop="'otherWaterTerminalListForNoH.' + index + '.readNumber'" >
                  <el-input v-model="domain.readNumber" placeholder="正向读数"></el-input>
                </el-form-item>
              </el-col>
              <el-col class="line" :span="1">-</el-col>
              <el-col :span="7">
                <el-form-item :prop="'otherWaterTerminalListForNoH.' + index + '.reverseNumber'" >
                  <el-input v-model="domain.reverseNumber" placeholder="反向读数"></el-input>
                </el-form-item>
              </el-col>
            </div>
            </el-form-item>
            <el-divider content-position="left" v-show="leaveForm.otherElectricityTerminalListForNoH!= null && leaveForm.otherElectricityTerminalListForNoH.length!==0">电表设备</el-divider>
          <el-form-item
            v-for="(domain, index) in leaveForm.otherElectricityTerminalListForNoH"
              :label="'安装地址：'+domain.terminalName+',设备编号：'+domain.terminalId"
              :key="domain.locationNb"
          > 
            <div>
              <el-form-item :prop="'otherElectricityTerminalListForNoH.' + index + '.totalFlow'" ><!-- :rules="[{ required: true, message: '读数不能为空', trigger: 'blur' },{ validator:checkNumber, trigger: 'blur' }]"-->
                <el-input v-model="domain.totalFlow" placeholder="组合有功电量"></el-input>
              </el-form-item>
            </div>
            
          </el-form-item>
        </div>
        <div v-show="steps_active==3">
          {{ active3Value }}
          
        </div>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="changStepsRemove" v-show="steps_active !==1">上一步</el-button>
        <el-button type="primary" @click="changStepsAdd" v-show="steps_active !==3">下一步</el-button>
        <el-button type="primary" @click="submitLeaveForm" v-show="steps_active ==3 && !Leaveflag==true">确 定</el-button>
        <el-button @click="leaveCancel">取 消</el-button>
      </div>
    </el-dialog>





    <!-- 挂接 -->
    <el-dialog :title="setTitle" :visible.sync="setOpen" width="980px" :close-on-click-modal="false" append-to-body>
      <div style="height: 400px;">
        <el-form ref="setForm" label-width="0px" style="display: flex;">
          <el-form-item label="" prop="">
            <el-button type="primary" plain icon="el-icon-plus" @click="handleTerminalAdd" >新增</el-button>
          </el-form-item>
          <el-form-item label="" prop="" style="margin-left: 10px;">
            <el-select v-model="powerType" placeholder="请选择"  style="width: 200px" @change="handleEnergyTypeChange">
              <el-option v-for="dict in dict.type.energy_use_classification"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <el-table v-loading="setLoading" :data="setDataList" size="mini" row-key="id" border height="calc(100% - 50px)">
          <!-- <el-table-column label="用户名称" align="center" prop="userName" min-width="130" :show-overflow-tooltip="true"/>
          <el-table-column label="用户编号" align="center" prop="userId" width="100" /> -->
          <el-table-column label="设备编号" align="center" prop="terminalId" width="100" />
          <el-table-column label="安装地址" align="center" prop="installAddress" width="100" />
          <el-table-column label="能耗类型" align="center" prop="energyType" width="80" >
            <template slot-scope="scope">
              <dict-tag :options="dict.type.energy_use_classification" :value="scope.row.energyType+''"/>
            </template>
          </el-table-column>

          <el-table-column label="计算类型" align="center" prop="calcType" width="100">
            <template slot-scope="scope">
              <el-select v-model="scope.row.calcType" placeholder="请选择" style="width: 100%" @change="handleEditChange(scope.row)">
                <el-option v-for="dict in dict.type.user_terminalsxb_calc_type" :key="dict.value" :label="dict.label"
                          :value="parseInt(dict.value)"></el-option>
              </el-select>
            </template>
          </el-table-column>

          <el-table-column label="比率" align="center" prop="calcRate" width="240">
            <template slot-scope="scope">
               <el-input-number
                      v-model="scope.row.calcRate"
                      :precision="2"
                       @change.native="handleEditChange(scope.row)"
                      :step="0.01"
                    ></el-input-number>
            </template>
          </el-table-column>

          <el-table-column label="更改时间" align="center" prop="updateTime" width="150" />
          <el-table-column label="状态" align="center" prop="status" width="100" >
            <template slot-scope="scope">
              <div>{{scope.row.status === 1 ? '在场' : scope.row.status === 2 ? '离场' : '删除'}}</div>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="50">
            <template slot-scope="scope">
              <el-tooltip effect="dark" content="删除" placement="top">
                <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-delete"
                    @click="handleBindTerminalDelete(scope.row)"
                >
                </el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div> -->
    </el-dialog>


    <!-- 挂接-新增按钮弹框 -->
    <el-dialog title="选取设备" :visible.sync="terminalOpen" width="650px" :close-on-click-modal="false" append-to-body>
      <div style="height: 400px;">
        <el-form ref="terminalForm" :model="terminalQueryParams" label-width="70px" style="display: flex;">
          <!-- <el-form-item label="用户名称" prop="userName">
            <el-input :size="formItemSize" v-model="terminalQueryParams.userName" placeholder="请输入用户名称" clearable />
          </el-form-item> -->
          <el-form-item label="设备编号" prop="terminalId" style="margin-left: 10px;">
            <el-input :size="formItemSize" v-model="terminalQueryParams.terminalId" placeholder="请输入设备编号" clearable />
          </el-form-item>
          <div style="margin-left: 10px;height: 30px;line-height: 36px;">
            <el-button  type="primary" plain icon="el-icon-search" @click="handleTerminalQuery" size="mini">查询</el-button>
          </div>
        </el-form>
        <el-table v-loading="terminalLoading" :data="terminalDataList" size="mini" row-key="id" border height="calc(100% - 102px)"
          @selection-change="handleSelectionChange2">
          <el-table-column type="selection" width="55" align="center"/>
          <!-- <el-table-column label="用户编号" align="center" prop="userId" width="120" />
          <el-table-column label="用户名称" align="center" prop="userName" width="120" :show-overflow-tooltip="true"/> -->
          <el-table-column label="设备编号" align="center" prop="terminalId" width="120" />
          <el-table-column label="安装地址" align="center" prop="installAddress" min-width="120" />

        </el-table>
        <pagination
          v-show="terminalTotal>0"
          :total="terminalTotal"
          pager-count="5"
          :page.sync="terminalQueryParams.pageNum"
          :limit.sync="terminalQueryParams.pageSize"
          layout="total, sizes, prev, pager, next"
          @pagination="getTerminalDataList"
        />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="terminalSubmitForm">确 定</el-button>
        <el-button @click="terminalCancel">取 消</el-button>
      </div>
    </el-dialog>





  </div>
</template>

<script>
  import { listElecTerminalXbForGJ } from "@/api/basedata/elecTerminalXb";
  import {listTerminalxbForGJ } from "@/api/record/terminalxb";
import {getPublicShare, listPublicShare, addPublicShare,updatePublicShare
    ,delPublicShare,transferPublicShare} from "@/api/basedata/publicShare";
import {listPublicShareJoinAll,delPublicShareJoin,addBindUser,editBindUser
    ,getUserListInSelect,getUserPageForGJ} from "@/api/basedata/publicShareJoin";

import {listUserTerminalsxbJoin,getUserTerminalsxbJoin,adduserTerminalsxbJoinList ,updateUserTerminalsxbJoin
    ,delUserTerminalsxbJoin , listUserTerminalsxbJoinMore} from "@/api/basedata/userTerminalsxbJoin";



import { deptList } from '@/api/system/dept.js'
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {listUsersxb, getUsersxb, delUsersxb, addUsersxb,cloneUsersxb, updateUsersxb} from "@/api/record/usersxb";
import {getUserTerminalInPublicShareList,dealUserLeave} from "@/api/basedata/publicShareJoin";
import {getUserTerminalList,getOtherTerminalList,insertBillForUseLeve,dealUserLeaveForinsertHistoryData,synchronizationWaterData,synchronizationEletricityData} from "@/api/datastatistics/bill/bill";
import {getToken} from "@/utils/auth";

export default {
  name: "TerminalUsers",
  components: {Treeselect},
  dicts: ['yes_no', 'belong_department', 'user_mark','leave_bill_status','is_prepayment'
  ,'energy_use_classification','user_terminalsxb_calc_type'],
  data() {
    var checkNumber = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('读数不能为空'));
      }
      setTimeout(() => {
        if (!isNaN(value) && !isNaN(parseFloat(value))) {
          callback();
        } else {
          callback(new Error('请输入数字值'));
        }
      }, 200);
    };
    return {
        // 时间范围
      dateRangeReadDate: [],
      active3Value:"",
      leaverow: null,
      userdepartureTime:"",
      steps_active:1,
      title_userLeve:"离场开账",
      isFullscreen: false,
      formItemSize: 'mini',
      // 弹出层标题
      setTitle: "",
      // 是否显示弹出层
      setOpen: false,
      powerType:'1',
      setLoading:false,
      setDataList:[],
      selectedPublicShareId:null,
      selectedPublicShareName:'',
      terminalOpen:false,
      terminalTotal:0,
      terminalQueryParams:{
        pageNum: 1,
        pageSize: 20,
        terminalId:'',
        // userId:'',
        // userName:''
      },
      terminalLoading:false,
      terminalDataList:[],
      selectedTerminalList:[],


      selectedUserXbId:null,
      selectedUserXbName:'',






      ////////////////////
      // 客户下拉框中的数据
      deptOption: [],
      screenHeight: null,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 区域管理表格数据
      usersxbList: [],
      // 弹出层标题
      title: "",
      // 复制用户弹出层标题
      clonetitle: "",
      // 是否显示弹出层
      open: false,
      //复制用户弹出层
      cloneopen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        userName: null,
        userId: null,
        tenantId: null,
        params:{
          departureTime:[]
        }
      },
      ids: [],
      // 列信息
      columns: [
        {key: 0, label: `用户编号`, visible: true},
        {key: 1, label: `用户名称`, visible: true},
        {key: 2, label: `用户手机号码`, visible: true},
        {key: 3, label: `证件类型`, visible: true},
        {key: 4, label: `证件号码`, visible: true},
        {key: 5, label: `用户通讯地址`, visible: true},
        {key: 6, label: `备注`, visible: true},
        {key: 7, label: `用户状态`, visible: true},
        {key: 8, label: `立户时间`, visible: true},
        {key: 9, label: `所属客户`, visible: true},
        {key: 10, label: `品牌名称`, visible: true},
      ],
      // 默认排序
      defaultSort: {prop: 'createTime', order: 'descending'},
      // 表单参数
      form: {
        userId:null,
        userName:null,
        userPhone:null,
        idType:null,
        userCode:null,
        userAddress:null,
        remark:null,
        userMark:1,
        isPrepayment:0,
      },
      // 表单参数
      cloneform: {
        userId:null,
        userName:null,
        userPhone:null,
        idType:null,
        userCode:null,
        userAddress:null,
        remark:null,
        userMark:1,
        isPrepayment:0,
      },
      // 表单校验
      rules: {
        parentId: [
          {required: true, message: "请选择父级区域", trigger: "change"}
        ],
        userId: [
          {required: true, message: "请输入用户编号", trigger: "blur"}
        ],
        userName: [
          {required: true, message: "请输入用户名称", trigger: "blur"}
        ],
        tenantId: [
          {required: true, message: "请选择所属客户", trigger: "change"}
        ],
      },
      maxShow: 4,
      formItemSize: 'mini',
      collapseAble: false,
      fold: false,
      labelWidth: '80px',
      uploadVisible: true,
      // 导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/basedata/usersxb/importData"
      },
      leaveOpen:false,
      Leaveflag:false,
      leaveForm:{

      }
    };
  },
  created() {
    this.getList();
    this.screenHeight = document.body.clientHeight
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    }
  },
  computed: {
    getAvailableHeight() {
      return this.screenHeight - (this.showSearch ? 240 : 195)
    },
  },
  methods: {
    changStepsAdd(){
      this.steps_active = this.steps_active + 1;
    },
    changStepsRemove(){
      this.steps_active = this.steps_active - 1;
    },
    toggleMaximize() {
      this.isFullscreen = !this.isFullscreen;
      
      // 你可以在这里添加一些额外的逻辑，比如记录窗口位置等
    },
    /** 挂接start */
    //查询设备
    handleTerminalQuery(){
      this.getTerminalDataList();
    },
    /** 设备提交按钮 */
    terminalSubmitForm() {
      adduserTerminalsxbJoinList(this.selectedTerminalList).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.getBindList();
              this.terminalOpen = false;
            });
    },
    // 多选框选中数据
    handleSelectionChange2(selection) {
      let that = this;
      that.selectedTerminalList = [];
      for(let i=0;i<selection.length;i++){
        let item = selection[i];
        that.selectedTerminalList.push({
          userId:that.selectedUserXbId,
          // terminalId:item.terminalId,
          // userId:item.userId,
          locationNb:item.locationNb,
          energyType:that.powerType,
          terminalId:item.terminalId,
          status: 1
        });
      }
    },
    // 设备取消按钮
    terminalCancel() {
      this.terminalOpen = false;
      this.terminalQueryParams = {pageNum: 1,
        pageSize: 20,
        // userId:'',
        // userName:''
        terminalId:'',
      };
    },
    /** 区域设备配置-新增打开弹框 */
    handleTerminalAdd() {
      this.terminalQueryParams = {pageNum: 1,
        pageSize: 20,
        // userId:'',
        // userName:''
        terminalId:'',
      };
      this.terminalOpen = true;
      this.getTerminalDataList();
    },
    getTerminalDataList(){
      this.terminalLoading = true;
      // this.terminalQueryParams.areaOrPublicShare = 2;
      this.terminalQueryParams.userXbId = this.selectedUserXbId
      if(this.powerType == 1){
        listElecTerminalXbForGJ(this.terminalQueryParams).then(response => {
          this.terminalDataList = response.rows;
          this.terminalTotal = response.total;
          this.terminalLoading = false;
        });
      }else{
        listTerminalxbForGJ(this.terminalQueryParams).then(response => {
          this.terminalDataList = response.rows;
          this.terminalTotal = response.total;
          this.terminalLoading = false;
        });
      }
      // getUserPageForGJ(this.terminalQueryParams).then(response => {
      //   this.terminalDataList = response.rows;
      //   this.terminalTotal = response.total;
      //   this.terminalLoading = false;
      // });
    },
    // 区域设备配置
    handleSetting(row){
      this.setTitle="["+row.userName+"]用户设备挂接";
      this.setOpen = true;
      // this.selectedPublicShareId = row.id;
      // this.selectedPublicShareName = row.publicShareName;
      // this.getBindList();

      this.selectedUserXbId = row.userId;
      this.selectedUserXbName = row.userName;
      this.getBindList();


    },
    /** 删除按钮操作-区域设备配置 */
    handleBindTerminalDelete(row) {
      const id = row.id
      this.$modal.confirm('是否确认删除所选记录？').then(function () {
        return delUserTerminalsxbJoin(id);
      }).then(() => {
        this.getBindList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    handleChange1(val){

      this.powerType = val+'';
      console.log(this.powerType);
    },
    //区域设备配置-选择能耗类型
    handleEnergyTypeChange(val){
      this.powerType = val+'';
      this.getBindList();
    },
    getBindList(){
      //加载数据
      this.setLoading = true;
      // listUserTerminalsxbJoin({publicShareId:this.selectedPublicShareId,energyType:this.powerType}).then(response => {
      listUserTerminalsxbJoinMore({userId:this.selectedUserXbId,energyType:this.powerType}).then(response => {
         this.setDataList = [];
        if(response.rows){
          this.setDataList = response.rows;
        }
        this.setLoading = false;
      });
    },
    handleEditChange(row){
      updateUserTerminalsxbJoin(row).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.getBindList();
      });
    },
    /** 挂接end */



    //  // 区域设备配置
    // handleSetting(row){
    //   this.setTitle="["+row.publicShareName+"]用户设备挂接";
    //   this.setOpen = true;
    //   this.selectedPublicShareId = row.id;
    //   this.selectedPublicShareName = row.publicShareName;
    //   // this.powerType = '1';
    //   this.getBindList();
    // },


    // 获取所有客户
    getDeptList() {
      deptList().then(response => {
        this.deptOption = response.data
      })
    },
    /** 排序触发事件 */
    handleSorterChange({column, prop, order}) {
      this.queryParams.orderByColumn = prop
      this.queryParams.isAsc = order
      this.getList()
    },
    /** 检查设置排序字段 */
    checkSortColumn() {
      if (!this.queryParams.orderByColumn) {
        this.queryParams.orderByColumn = this.defaultSort.prop
        this.queryParams.isAsc = this.defaultSort.order
      }
    },

    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户档案导入";
      this.upload.open = true;
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", {dangerouslyUseHTMLString: true});
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    /** 查询区域管理列表 */
    getList() {
      this.checkSortColumn()
      this.loading = true;
      if (null != this.dateRangeReadDate && '' != this.dateRangeReadDate) {
        this.queryParams.params["departureTime"] = this.dateRangeReadDate;
      }
      listUsersxb(this.queryParams).then(response => {
        this.usersxbList = response.rows;
        this.total = response.total
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    clonecancel(){
      this.cloneopen = false;
      this.resetclone();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        userName: null,
        userPhone: null,
        idType: null,
        userCode: null,
        userAddress: null,
        remark: null,
        userMark: 1,
        isPrepayment:0,
      };
      this.resetForm("form");
    },
    // 克隆表单重置
    resetclone() {
      this.cloneform = {
        id: null,
        userId: null,
        userName: null,
        userPhone: null,
        idType: null,
        userCode: null,
        userAddress: null,
        remark: null,
        userMark: 1,
        isPrepayment:0,
      };
      this.resetForm("cloneform");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRangeReadDate = []
      this.queryParams.params["departureTime"]  = []
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      if (row) {
        this.form.parentId = row.id
      }
      this.open = true;
      this.title = "添加用户管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id
      getUsersxb(id).then(response => {
        this.form = response.data;
        // this.form.parentId = (response.data.parentId === 'root' ? undefined : response.data.parentId)
        this.open = true;
        this.title = "修改用户管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateUsersxb(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUsersxb(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    //克隆提交
    cloneSubmitForm() {
      this.$refs["cloneform"].validate(valid => {
        if (valid) {
          // if (this.form.id != null) {
          //   updateUsersxb(this.form).then(response => {
          //     this.$modal.msgSuccess("修改成功");
          //     this.open = false;
          //     this.getList();
          //   });
          // } else {

          // }
          cloneUsersxb(this.cloneform).then(response => {
              this.$modal.msgSuccess("克隆成功");
              this.cloneopen = false;
              this.getList();
            });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const IDs = row.id || this.ids
      this.$modal.confirm('是否确认删除所选记录？').then(function () {
        return delUsersxb(IDs);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('basedata/usersxb/export', {
        ...this.queryParams
      }, `区域信息.xlsx`)
    },
    // 下载模板
    handleUpload() {
      this.download('basedata/usersxb/getImportTemplate', {}, `用户档案模板.xlsx`)
    },
    // 展开折叠按钮
    shiftCollapseAble() {
      this.fold = !this.fold
      this.minShowControl()
    },
    // 通过maxShow控制元素显示/折叠
    minShowControl() {
      const group = window.document.querySelectorAll(`#searchFilter .el-form-item.el-form-item--${this.formItemSize}`)
      const len = group?.length ? group?.length : 0
      if (this.maxShow < len) {
        group.forEach((item, index) => {
          if (index > this.maxShow - 1 && index < len) {
            item.hidden = !this.fold
          }
        })
        this.collapseAble = true
      } else {
        this.collapseAble = false
      }
    },
    /** 办理离场 */
    handleLeave(row){
      this.isFullscreen = false;
      this.leaveForm = {};
      this.leaveForm.userId = row.userId;
      this.leaveOpen = true;
      this.leaverow = row;
      this.steps_active = 1;
      this.userdepartureTime = null;
      this.active3Value = "确认生成用户离场报表！";
      this.Leaveflag = false;
    },
    //获取离场用户信息
    async getTerminalList(){
      
      let row = this.leaverow;
      //this.$set( this.leaveForm, 'userdepartureTime', this.userdepartureTime);
     //获取离场用户信息
     if(this.userdepartureTime == null || this.userdepartureTime== ""){
      this.$modal.msgWarning("请填写离场时间");
  
     }else{
      this.$modal.loading("正在同步水表、电表数据，请等待···");
      await synchronizationWaterData({userId:row.userId,departureTime:this.userdepartureTime});
      await synchronizationEletricityData({userId:row.userId,departureTime:this.userdepartureTime});
      this.$modal.closeLoading();
      getUserTerminalList({userId:row.userId,departureTime:this.userdepartureTime}).then(response => {
        let data = response.data;
        //当前用户未绑定设备
        if(data.userElectricityTerminalListForNoH === null || data.userWaterTerminalListForNoH.length==0){
          this.$modal.msgWarning("户内表均抄回");
        }
        this.leaveForm = data;
      });
      
      // getOtherTerminalList({userId:row.userId,departureTime:this.userdepartureTime}).then(response => {
      //   let data = response.data;
      //   //当前用户未绑定设备
      //   if(data.otherWaterTerminalListForNoH === null || data.otherElectricityTerminalListForNoH.length==0){
      //     this.$modal.msgWarning("公摊相关设备数据均抄回！");
      //     this.$set( this.leaveForm, 'otherWaterTerminalListForNoH', {});
      //     this.$set( this.leaveForm, 'otherElectricityTerminalListForNoH',{});
      //   }else{
      //     this.$set( this.leaveForm, 'otherWaterTerminalListForNoH', data.otherWaterTerminalListForNoH);
      //     this.$set( this.leaveForm, 'otherElectricityTerminalListForNoH', data.otherElectricityTerminalListForNoH);
      //   }
      // });
     }
    
    },
    //克隆用户
    handleClone(row){
      const IDs = row.id || this.ids
      // this.$modal.confirm('是否确认克隆所选用户？').then(function () {
      // });
      this.resetclone();
        if (row) {
          this.cloneform.remark = row.userId
        }
        this.cloneopen = true;
        this.clonetitle = "克隆用户";
    },
    submitLeaveForm(){
      debugger
     

      //先插入用户挂接设备、公摊相关设备
      this.$refs["leaveForm"].validate(valid => {
       
        if (valid) {
          let row = this.leaverow;
          this.$set( this.leaveForm, 'userdepartureTime', this.userdepartureTime);
          dealUserLeave(this.leaveForm).then(response => {
              this.active3Value =  "<span>用户离场前户内表数据补录成功！</span>";
              this.$modal.loading("正在用户离场报表处理中...");
            //   //开账验证
            // getUserTerminalList({userId:row.userId,departureTime:this.userdepartureTime}).then(response => {
            //   let data = response.data;
            //   //当前用户未绑定设备
            //   if(data.userElectricityTerminalListForNoH === null && data.userWaterTerminalListForNoH.length==0){
            //     this.active3Value = this.active3Value+ "<span>用户离场验证成功！</span> <el-divider></el-divider><span>正在开账中...</span>";
            //   }
            // });
            //开账逻辑 
            insertBillForUseLeve({userId:row.userId,departureTime:this.userdepartureTime}).then(response => {
              let data = response.data;
              //当前用户未绑定设备
              if(data == 1 ){
                this.active3Value = this.active3Value+ "<el-divider></el-divider><span>开账成功！</span>";
                //this.$modal.msgSuccess("开账成功！");
                this.Leaveflag = true;
              }else{
                this.active3Value = this.active3Value+ "<el-divider></el-divider><span>开账失败！</span>";
                //this.$modal.msgWarning("开账失败！");
              }
              this.$modal.closeLoading();
            });
          });
          // dealUserLeave(this.leaveForm).then(response => {
          //   this.$modal.msgSuccess("离场成功");
          //   this.leaveOpen = false;
          //   this.getList();
          // });
        }
       
      });
     
    },
    leaveCancel() {
      this.leaveOpen = false;
      this.leaveForm = {};
    },
    checkNumber(rule, value, callback) {
      if (!value) {
        return callback(new Error('读数不能为空'));
      }
      setTimeout(() => {
        if (!isNaN(value) && !isNaN(parseFloat(value))) {
          callback();
        } else {
          callback(new Error('请输入数字值'));
        }
      }, 200);
    }
  },
  mounted() {
    this.getDeptList();
    // 通过最大显示个数控制展开/折叠
    if (this.maxShow > 0) {
      this.minShowControl()
    }
  },
};
</script>
<style scoped lang="scss">
.div-height-minus{
  height: 500px;
  overflow-y: auto;
}
.div-height-full-screen{
 height:  calc(100vh - 150px);
 overflow-y: auto;
}
/* 自定义标题栏的布局 */
.custom-dialog-header {
  display: flex;
  justify-content: space-between; /* 标题和按钮组两端对齐 */
  align-items: center;           /* 垂直居中 */
  width: 100%;                   /* 确保占据整个标题栏宽度 */
}

/* 自定义标题文本样式 */
.custom-dialog-title {
  font-size: 16px;
  // font-weight: 700;
  color: var(--el-text-color-primary); /* 使用 Element UI 的主题变量 */
  line-height: 1;
}

/* 自定义操作按钮组 */
.custom-dialog-actions {
  display: flex;
  gap: 6px; /* 按钮之间的间距 */
}

/* 
 * 自定义按钮的基础样式
 * 模仿 Element UI 原始关闭按钮的尺寸和行为
 */
.custom-dialog-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  margin: 0;
  color: var(--el-text-color-placeholder); /* 默认颜色偏灰 */
  border-radius: 50%; /* 圆形按钮更美观 */
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease; /* 平滑过渡效果 */
}

/* 鼠标悬停时的样式 */
.custom-dialog-btn:hover {
  color: var(--el-color-primary); /* 悬停时变为主题色 */
  background-color: var(--el-color-primary-light-9); /* 轻微的背景色变化 */
}

/* 
 * 特别为关闭按钮添加样式
 * 如果你想让关闭按钮和最大化按钮在视觉上有所区分，可以单独设置
 */
.custom-dialog-close-btn:hover {
  color: var(--el-color-danger); /* 例如，让关闭按钮悬停时显示警告色 */
  background-color: var(--el-color-danger-light-9);
}


/* 核心样式：让自定义标题区域与操作按钮区水平排列 */
// .el-dialog__header {
//   display: flex;
//   align-items: center;
// }

// .custom-dialog-header {
//   flex: 1; /* 关键：让标题区域占据剩余的所有空间 */
//   display: flex;
//   justify-content: space-between; /* 让标题文字和自定义按钮分开 */
//   align-items: center;
//   padding-right: 16px; /* 增加一些与关闭按钮的间距 */
// }

.form_col {
  width: 80%;

  ::v-deep .el-form {
    width: 100%;
  }

  ::v-deep .el-form-item {
    width: 18%;
  }
}

.form_query {
  width: 20%;
  text-align: right;
}
.line{
  text-align: center;
}
::v-deep .el-form--label-top .el-form-item__label{
  padding:0px !important
}
</style>
